#pragma once

#include "../common/SquareGrid.h"
#include "../common/GenericCA.h"


class SeparationCA : 
  public Generic2DCA<SeparationCA, char, CASquareGrid>
{
  typedef Generic2DCA<SeparationCA, char, CASquareGrid> Base;
public:
  SeparationCA(int width, int height) : Base(width, height) {}

private:
  struct Visitor : public GridType::AllNeighbourVisitor<Visitor>
  {
    Visitor(SeparationCA & parent) {}
    void walkCell()
    {
      static const char lookup[10] = {0, 0, 0, 0, 1, 0, 1, 1, 1, 1};
      int sum = C() + R() + U() + L() + D() + UR() + UL() + DL() + DR();
      out() = lookup[sum];
    }
  };
};

